//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//

package SaveServlet.course;

import com.lyq.bean.service.C_Service;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet(
        name = "AddCourse_Servlet",
        urlPatterns = {"/AddCourse_Servlet"}
)
public class AddCourse_Servlet extends HttpServlet {
    private static final long serialVersionUID = 1L;

    public AddCourse_Servlet() {
    }

    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String name = request.getParameter("name");
        String time = request.getParameter("time");
        String place = request.getParameter("place");
        String credit = request.getParameter("credit");
        String teacher = request.getParameter("teacher");
        String limitnum = request.getParameter("limitnum");
        String No = request.getParameter("No");
        // 获取新增的参数
        String courseType = request.getParameter("courseType");
        String campus = request.getParameter("campus");
        String category = request.getParameter("category");
        int major_id = Integer.parseInt(request.getParameter("major_id"));
        int year_id = Integer.parseInt(request.getParameter("year_id"));
        Boolean bool = (new C_Service()).add_C(No, name, time, place, credit, teacher,limitnum, courseType, campus,category,major_id,year_id);
        if (bool) {
            request.getSession().setAttribute("message", "添加课程分配成功！");
        } else {
            request.getSession().setAttribute("message", "该图书编号已存在，添加课程分配失败！");
        }

        request.getSession().setAttribute("url", "jsp/course/m/AddCourse.jsp");
        request.getRequestDispatcher("Message.jsp").forward(request, response);
    }
}